import SparkMD5 from './spark-md5.js'
export function createChunk(file, index, chunkSize) {
    return new Promise((resolve) => {
        const start = index * chunkSize
        const end = start + chunkSize
        const spark = new SparkMD5.ArrayBuffer()
        const fileReader = new FileReader()
        const blob = file.slice(start, end)
        fileReader.onprogress = (e) => {
            console.log('加载中...')
        }
        fileReader.onload = (e) => {
            console.log('第' + (index + 1) + '个文件加载完成')
            spark.append(e.target.result) // md5 计算加密时会消耗时间，所以要使用多线程            
            resolve({
                start,
                end,
                index,
                hash: spark.end(),
                blob
            })
        }
        fileReader.onerror = (e) => {
            console.error('文件读取失败:', e)
            resolve(undefined)  // 处理错误情况
        }
        fileReader.readAsArrayBuffer(blob)
    })
}